import java.util.*;

public class NutritionForm
{
    public NutritionForm()
    {
    }
    public static double endomorphy(
        float size,
        float c_tricep,
        float c_subscapularis,
        float c_suprailiac
        )
    {
        double x;
        if(size == 0)
        	return Double.NaN;
        x = (c_tricep + c_subscapularis + c_suprailiac)*(170.18F/size);
        return 0.7182F + 0.1451F*x - 0.00068F*Math.pow(x,2) + 0.0000014F*Math.pow(x,3);
    }
    public static double mesomorphy(
        float d_humeral,
        float d_femoral,
        float g_contractedArm,
        float g_leg,
        float size,
        float c_tricep,
        float c_leg
        )
    {
        return 0.858*d_humeral + 0.601*d_femoral + 0.188*(g_contractedArm-c_tricep) + 0.161*(g_leg-c_leg) - 0.131*size + 4.5;
    }
    public static double ectomorphy(
        float size,
        float currentWeight
        )
    {
    	if(currentWeight == 0)
    		return Double.NaN;
        double index = size/Math.cbrt(currentWeight);
        if(40.75 <= index)
            return (index*0.732) - 28.58;
        else if((38.38 < index)&&(index < 40.75))
            return (index*0.463) - 17.63;
        else
            return 0.1;
    }
    public static float getDecimalAge(int[] ddmmyy_1,int[] ddmmyy_2)
    {
        int year_1 = ddmmyy_1[2];
        int month_1 = ddmmyy_1[1];
        int day_1 = ddmmyy_1[0];
        int year_2 = ddmmyy_2[2];
        int month_2 = ddmmyy_2[1];
        int day_2 = ddmmyy_2[0];
        if((31<day_1)||(31<day_2))
            return -1;
        if((12<month_1)||(12<month_2))
            return -1;
        float decAge_1 = year_1 + TABLE_DEC_AGE[month_1-1][day_1-1];
        float decAge_2 = year_2 + TABLE_DEC_AGE[month_2-1][day_2-1];
        if(decAge_1 < decAge_2)
            return decAge_2 - decAge_1;
        else
            return decAge_1 - decAge_2;
    }
    public static float getDecimalAge(Date date_1,Date date_2)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date_1);
        int year_1 = calendar.get(Calendar.YEAR);
        int month_1 = calendar.get(Calendar.MONTH);
        int day_1 = calendar.get(Calendar.DAY_OF_MONTH);
        calendar.setTime(date_2);
        int year_2 = calendar.get(Calendar.YEAR);
        int month_2 = calendar.get(Calendar.MONTH);
        int day_2 = calendar.get(Calendar.DAY_OF_MONTH);
        float decAge_1 = year_1 + TABLE_DEC_AGE[day_1-1][month_1-1];
        float decAge_2 = year_2 + TABLE_DEC_AGE[day_2-1][month_2-1];
        if(decAge_1 < decAge_2)
            return decAge_2 - decAge_1;
        else
            return decAge_1 - decAge_2;
    }
    private static final float[][] TABLE_DEC_AGE = {
        {   0F, .085F,    .162F,   .247F,   .329F,   .414F,   .496F,   .581F,   .666F,   .778F,   .833F,   .915F},
        {.003F, .088F,    .164F,   .249F,   .332F,   .416F,   .499F,   .584F,   .668F,   .751F,   .836F,   .918F},
        {.005F, .090F,    .167F,   .252F,   .334F,   .419F,   .501F,   .586F,   .671F,   .753F,   .838F,   .921F},
        {.008F, .093F,    .170F,   .255F,   .337F,   .422F,   .504F,   .589F,   .674F,   .756F,   .841F,   .923F},
        {.011F, .096F,    .173F,   .258F,   .340F,   .425F,   .507F,   .592F,   .677F,   .759F,   .844F,   .926F},
        {.014F, .099F,    .175F,   .260F,   .342F,   .427F,   .510F,   .595F,   .679F,   .762F,   .847F,   .929F},
        {.016F, .101F,    .178F,   .263F,   .345F,   .430F,   .512F,   .597F,   .682F,   .764F,   .849F,   .932F},
        {.019F, .104F,    .181F,   .266F,   .348F,   .433F,   .515F,   .600F,   .685F,   .767F,   .852F,   .934F},
        {.022F, .107F,    .184F,   .268F,   .351F,   .436F,   .518F,   .603F,   .686F,   .770F,   .855F,   .937F},
        {.025F, .110F,    .186F,   .271F,   .353F,   .438F,   .521F,   .605F,   .690F,   .773F,   .858F,   .940F},
        {.027F, .112F,    .189F,   .274F,   .356F,   .441F,   .523F,   .608F,   .693F,   .775F,   .860F,   .942F},
        {.030F, .115F,    .192F,   .277F,   .359F,   .444F,   .526F,   .611F,   .696F,   .778F,   .863F,   .945F},
        {.033F, .118F,    .195F,   .279F,   .362F,   .447F,   .529F,   .614F,   .699F,   .781F,   .866F,   .948F},
        {.036F, .121F,    .197F,   .282F,   .364F,   .449F,   .532F,   .616F,   .701F,   .784F,   .968F,   .951F},
        {.038F, .123F,    .200F,   .285F,   .367F,   .452F,   .534F,   .619F,   .704F,   .786F,   .871F,   .953F},
        {.041F, .126F,    .203F,   .288F,   .370F,   .455F,   .537F,   .622F,   .707F,   .789F,   .874F,   .956F},
        {.044F, .129F,    .205F,   .290F,   .373F,   .458F,   .540F,   .625F,   .710F,   .792F,   .877F,   .959F},
        {.047F, .132F,    .208F,   .293F,   .375F,   .460F,   .542F,   .627F,   .712F,   .795F,   .879F,   .962F},
        {.049F, .134F,    .211F,   .296F,   .378F,   .463F,   .545F,   .630F,   .715F,   .797F,   .882F,   .964F},
        {.052F, .137F,    .214F,   .299F,   .381F,   .466F,   .548F,   .633F,   .716F,   .800F,   .885F,   .967F},
        {.055F, .140F,    .216F,   .301F,   .384F,   .468F,   .551F,   .636F,   .721F,   .803F,   .888F,   .970F},
        {.058F, .142F,    .219F,   .304F,   .386F,   .471F,   .553F,   .630F,   .723F,   .805F,   .890F,   .973F},
        {.060F, .145F,    .222F,   .307F,   .385F,   .474F,   .556F,   .641F,   .726F,   .808F,   .893F,   .975F},
        {.063F, .148F,    .225F,   .310F,   .392F,   .477F,   .559F,   .644F,   .729F,   .811F,   .896F,   .978F},
        {.066F, .151F,    .227F,   .312F,   .395F,   .479F,   .752F,   .647F,   .731F,   .814F,   .899F,   .981F},
        {.068F, .153F,    .230F,   .315F,   .397F,   .482F,   .564F,   .649F,   .734F,   .816F,   .901F,   .984F},
        {.071F, .156F,    .233F,   .318F,   .400F,   .485F,   .567F,   .652F,   .737F,   .819F,   .904F,   .986F},
        {.074F, .159F,    .236F,   .321F,   .403F,   .488F,   .570F,   .655F,   .740F,   .822F,   .907F,   .989F},
        {.077F,   -1F,    .238F,   .323F,   .405F,   .490F,   .573F,   .658F,   .742F,   .825F,   .910F,   .992F},
        {.079F,   -1F,    .241F,   .326F,   .408F,   .493F,   .575F,   .660F,   .745F,   .827F,   .912F,   .995F},
        {.082F,   -1F,    .244F,     -1F,   .411F,     -1F,   .578F,   .663F,     -1F,   .830F,     -1F,   .997F}
    };

}
/*
    private static final int[][] TABLE_DEC_AGE = {
        {0,  85,    162,    247,    329,    414,    496,    581,    666,    778,    833,    915},
        {3,  8,     164,    249,    332,    416,    499,    584,    668,    751,    836,    918},
        {5,  90,    167,    252,    334,    419,    501,    586,    671,    753,    838,    921},
        {8,  93,    170,    255,    337,    422,    504,    589,    674,    756,    841,    923},
        {11, 96,    173,    258,    340,    425,    507,    592,    677,    759,    844,    926},
        {14, 99,    175,    260,    342,    427,    510,    595,    679,    762,    847,    929},
        {16, 101,   178,    263,    345,    430,    512,    597,    682,    764,    849,    932},
        {19, 104,   181,    266,    348,    433,    515,    600,    685,    767,    852,    934},
        {22, 107,   184,    268,    351,    436,    518,    603,    686,    770,    855,    937},
        {25, 110,   186,    271,    353,    438,    521,    605,    690,    773,    858,    940},
        {27, 112,   189,    274,    356,    441,    523,    608,    693,    775,    860,    942},
        {30, 115,   192,    277,    359,    444,    526,    611,    696,    778,    863,    945},
        {33, 118,   195,    279,    362,    447,    529,    614,    699,    781,    866,    948},
        {36, 121,   197,    282,    364,    449,    532,    616,    701,    784,    968,    951},
        {38, 123,   200,    285,    367,    452,    534,    619,    704,    786,    871,    953},
        {41, 126,   203,    288,    370,    455,    537,    622,    707,    789,    874,    956},
        {44, 129,   205,    290,    373,    458,    540,    625,    710,    792,    877,    959},
        {47, 132,   208,    293,    375,    460,    542,    627,    712,    795,    879,    962},
        {49, 134,   211,    296,    378,    463,    545,    630,    715,    797,    882,    964},
        {52, 137,   214,    299,    381,    466,    548,    633,    716,    800,    885,    967},
        {55, 140,   216,    301,    384,    468,    551,    636,    721,    803,    888,    970},
        {58, 142,   219,    304,    386,    471,    553,    630,    723,    805,    890,    973},
        {60, 145,   222,    307,    385,    474,    556,    641,    726,    808,    893,    975},
        {63, 148,   225,    310,    392,    477,    559,    644,    729,    811,    896,    978},
        {66, 151,   227,    312,    395,    479,    752,    647,    731,    814,    899,    981},
        {68, 153,   230,    315,    397,    482,    564,    649,    734,    816,    901,    984},
        {71, 156,   233,    318,    400,    485,    567,    652,    737,    819,    904,    986},
        {74, 159,   236,    321,    403,    488,    570,    655,    740,    822,    907,    989},
        {77, -1 ,   238,    323,    405,    490,    573,    658,    742,    825,    910,    992},
        {79, -1 ,   241,    326,    408,    493,    575,    660,    745,    827,    912,    995},
        {82, -1 ,   244,    -1 ,    411,    -1 ,    578,    663,    -1 ,    830,    -1 ,    997}
    };
*/
